/**
 * Created by fifths on 17-8-31.
 */

import {Injectable} from '@angular/core';
import {HttpService} from '../../../../lib/service/http.service';
import {adSystemApiUrl} from '../../../../../config/api';
import {Http, Headers, RequestOptions, RequestOptionsArgs} from '@angular/http';


@Injectable()
export class GoodsStatusService {

  constructor(private httpService: HttpService) {
  }

  // 获取商品列表
  getGoodsList(applet_uuid: string,
               page: number,
               pageSize: number,
               applet_goods_category_id?: number,
               status?: string, order?: string,
               keyword?: string) {
    const _applet_goods_category_id = applet_goods_category_id || '',
      _status = (status === '选择商品状态' ? '' : status) || '',
      _keyword = keyword || '';
    const _order = (order === 'none' ? '' : order) || '';
    const url = `${adSystemApiUrl}/v1/member/goods/list` +
      `?applet_uuid=${applet_uuid}&applet_goods_category_id=${_applet_goods_category_id}` +
      `&order=${_order}&status=${_status}&keyword=${_keyword}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取分组列表
  getGroupList(applet_uuid: number) {
    const url = `${adSystemApiUrl}/v1/member/applet_goods_category/list?applet_uuid=${applet_uuid}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品绑定了哪些分类
  getbindListAll(goods_id) {
    const url = `${adSystemApiUrl}/v1/member/applet_goods_category_relation/bindListAll?goods_id=${goods_id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 改变商品上下架状态
  changeGoodsStatus(data) {
    const url = `${adSystemApiUrl}/v1/member/goods/status`;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }
}
